<?php

App::uses('AppModel', 'Model');

class Payment extends AppModel {
    
    public $order = 'Payment.date DESC';
    
    public $belongsTo = array ('Campaign', 'Invoice');
    
    public $validate = array(
        'campaign_id' => array(
            'rule'    => 'notEmpty',
            'message' => 'Morate odabrati kampanju.'
        ),
        'invoice_id' => array(
            'rule'    => 'notEmpty',
            'message' => 'Morate odabrati fakturu.'
        ),
        'date' => array(
            'rule'    => 'notEmpty',
            'message' => 'Morate odabrati datum.'
        ),
        'amount' => array(
            'rule'       => '/^\d+(\.\d+)?$/',
            'allowEmpty' => false,
            'message'    => 'Morate uneti iznos.'
        )
    );
    
    public function getCampaignsPayments($campaignIds) {
        return $this->find('all', array(
            'conditions' => array(
                'Payment.campaign_id' => $campaignIds
            ),
            'order' => 'Payment.date'
        ));
    }
    
}

?>